package com.cad3d.filemanager.converter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.util.StrutsTypeConverter;

public class DateConverter extends StrutsTypeConverter{

	Logger logger = Logger.getLogger(DateConverter.class);
	
	@Override
	public Object convertFromString(Map context, String[] values, Class clazz) {
		try {
			DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
			Date date = df.parse(values[0]);
			return date;
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(ex.getMessage());
		}
		return null;
	}

	@Override
	public String convertToString(Map context, Object value) {
		DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
		return df.format(value);
	}
}
